package edu.unf.cen6940.service;

import edu.unf.cen6940.domain.Thesis;
import edu.unf.cen6940.domain.Thesistool;

import java.util.List;
import java.util.Set;

import org.junit.Test;

import org.junit.runner.RunWith;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import org.springframework.context.ApplicationContext;

import org.springframework.mock.web.MockHttpServletRequest;

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;

import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import org.springframework.test.context.support.DirtiesContextTestExecutionListener;

import org.springframework.test.context.transaction.TransactionalTestExecutionListener;

import org.springframework.transaction.annotation.Transactional;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.RequestScope;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.SessionScope;

/**
 * Class to run the service as a JUnit test. Each operation in the service is a separate test.
 *
 */

@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({
		DependencyInjectionTestExecutionListener.class,
		DirtiesContextTestExecutionListener.class,
		TransactionalTestExecutionListener.class })
@ContextConfiguration(locations = {
		"file:./resources/rms_test-security-context.xml",
		"file:./resources/rms_test-service-context.xml",
		"file:./resources/rms_test-dao-context.xml",
		"file:./resources/rms_test-web-context.xml" })
@Transactional
public class ThesistoolServiceTest {

	/**
	 * The Spring application context.
	 *
	 */
	@SuppressWarnings("unused")
	private ApplicationContext context;

	/**
	 * The service being tested, injected by Spring.
	 *
	 */
	@Autowired
	protected ThesistoolService service;

	/**
	 * Instantiates a new ThesistoolServiceTest.
	 *
	 */
	public ThesistoolServiceTest() {
		setupRequestContext();
	}

	/**
	 * Operation Unit Test
	 * Return all Thesistool entity
	 * 
	 */
	@Test
	public void findAllThesistools() {
		// TODO: JUnit - Populate test inputs for operation: findAllThesistools 
		Integer startResult = 0;
		Integer maxRows = 0;
		List<Thesistool> response = null;
		response = service.findAllThesistools(startResult, maxRows);
		// TODO: JUnit - Add assertions to test outputs of operation: findAllThesistools
	}

	/**
	 * Operation Unit Test
	 * Load an existing Thesistool entity
	 * 
	 */
	@Test
	public void loadThesistools() {
		Set<Thesistool> response = null;
		response = service.loadThesistools();
		// TODO: JUnit - Add assertions to test outputs of operation: loadThesistools
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Thesistool entity
	 * 
	 */
	@Test
	public void deleteThesistool() {
		// TODO: JUnit - Populate test inputs for operation: deleteThesistool 
		Thesistool thesistool = new edu.unf.cen6940.domain.Thesistool();
		service.deleteThesistool(thesistool);
	}

	/**
	 * Operation Unit Test
	 * Save an existing Thesis entity
	 * 
	 */
	@Test
	public void saveThesistoolThesises() {
		// TODO: JUnit - Populate test inputs for operation: saveThesistoolThesises 
		Integer thesisToolId = 0;
		Thesis related_thesises = new edu.unf.cen6940.domain.Thesis();
		Thesistool response = null;
		response = service.saveThesistoolThesises(thesisToolId, related_thesises);
		// TODO: JUnit - Add assertions to test outputs of operation: saveThesistoolThesises
	}

	/**
	 * Operation Unit Test
	 * Return a count of all Thesistool entity
	 * 
	 */
	@Test
	public void countThesistools() {
		Integer response = null;
		response = service.countThesistools();
		// TODO: JUnit - Add assertions to test outputs of operation: countThesistools
	}

	/**
	 * Operation Unit Test
	 */
	@Test
	public void findThesistoolByPrimaryKey() {
		// TODO: JUnit - Populate test inputs for operation: findThesistoolByPrimaryKey 
		Integer thesisToolId_1 = 0;
		Thesistool response = null;
		response = service.findThesistoolByPrimaryKey(thesisToolId_1);
		// TODO: JUnit - Add assertions to test outputs of operation: findThesistoolByPrimaryKey
	}

	/**
	 * Operation Unit Test
	 * Delete an existing Thesis entity
	 * 
	 */
	@Test
	public void deleteThesistoolThesises() {
		// TODO: JUnit - Populate test inputs for operation: deleteThesistoolThesises 
		Integer thesistool_thesisToolId = 0;
		Integer related_thesises_thesisId = 0;
		Thesistool response = null;
		response = service.deleteThesistoolThesises(thesistool_thesisToolId, related_thesises_thesisId);
		// TODO: JUnit - Add assertions to test outputs of operation: deleteThesistoolThesises
	}

	/**
	 * Operation Unit Test
	 * Save an existing Thesistool entity
	 * 
	 */
	@Test
	public void saveThesistool() {
		// TODO: JUnit - Populate test inputs for operation: saveThesistool 
		Thesistool thesistool_1 = new edu.unf.cen6940.domain.Thesistool();
		service.saveThesistool(thesistool_1);
	}

	/**
	 * Autowired to set the Spring application context.
	 *
	 */
	@Autowired
	public void setContext(ApplicationContext context) {
		this.context = context;
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("session", new SessionScope());
		((DefaultListableBeanFactory) context.getAutowireCapableBeanFactory()).registerScope("request", new RequestScope());
	}

	/**
	 * Sets Up the Request context
	 *
	 */
	private void setupRequestContext() {
		MockHttpServletRequest request = new MockHttpServletRequest();
		ServletRequestAttributes attributes = new ServletRequestAttributes(request);
		RequestContextHolder.setRequestAttributes(attributes);
	}
}
